home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: What are the differences between structures and classes in C++ ?
- Message-ID: <marnoldDpHvED.E0t@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <4k5m65$av@hpscit.sc.hp.com> <DpG53J.Hsz@presby.edu> <4k83j3$a56@hpscit.sc.hp.com>
- Date: Sun, 7 Apr 1996 13:42:13 GMT
- Sender: marnold@netcom23.netcom.com
-
- Raghuveera Ravinutala <raghur> writes:
-
- ><jtbell@presby.edu (Jon Bell)> wrote :
- >>the only *formal* difference between a class and a
- >>struct is that by default, class members are private whereas struct
- >>members are public.
-
- >Thanx. I am aware of this difference. I would like to know more, like,
- >inheritence etc..
-
- There is none, other the default protection state of members. This is
- what the original poster meant by only a formal difference. All the
- rules you know about classes in C++ also apply to structs. For example,
- the following two versions of Foo are precisely equivalent...
-
- // version #1, using class keyword
-
- class Foo: public Bar
- {
- public:
- // some public members
- private:
- // some private members
- };
-
- // version #2, using struct keyword
-
- struct Foo: public Bar
- {
- public:
- // some public members
- private:
- // some private members
- };
-
- ...since the protection of all members is explicit. And, the fact that
- Foo is a struct or class doesn't affect the inheritance from Bar (that
- is, whatever public interface Bar defines becomes part of Foo's, in
- either case, as expected).
-
- Structs can inherit from other structs and classes and can be inherited
- by other structs and classes. Structs can have virtual functions, member
- operators, constructors and destructors, you can create template structs,
- and so on.
-
- In other words, structs *are* classes.
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-